<?php 

$maxRows_data_menu = 20;
$pageNum_data_menu = 0;
if (isset($_GET['pageNum_data_menu'])) {
  $pageNum_data_menu = $_GET['pageNum_data_menu'];
}
$startRow_data_menu = $pageNum_data_menu * $maxRows_data_menu;
if ($_GET['sort']<>'no'){
mysql_select_db($database_konek, $konek);
$query_data_menu = "SELECT * FROM menu WHERE parent_m = 0 ORDER BY sortir_m ASC";
$query_limit_data_menu = sprintf("%s LIMIT %d, %d", $query_data_menu, $startRow_data_menu, $maxRows_data_menu);
$data_menu = mysql_query($query_limit_data_menu, $konek) or die(mysql_error());
$row_data_menu = mysql_fetch_assoc($data_menu);
} else {
mysql_select_db($database_konek, $konek);
$query_data_menu = "SELECT * FROM menu ORDER BY sortir_m ASC";
$query_limit_data_menu = sprintf("%s LIMIT %d, %d", $query_data_menu, $startRow_data_menu, $maxRows_data_menu);
$data_menu = mysql_query($query_limit_data_menu, $konek) or die(mysql_error());
$row_data_menu = mysql_fetch_assoc($data_menu);	
}
if (isset($_GET['totalRows_data_menu'])) {
  $totalRows_data_menu = $_GET['totalRows_data_menu'];
} else {
  $all_data_menu = mysql_query($query_data_menu);
  $totalRows_data_menu = mysql_num_rows($all_data_menu);
}
$totalPages_data_menu = ceil($totalRows_data_menu/$maxRows_data_menu)-1;

$queryString_data_menu = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_data_menu") == false && 
        stristr($param, "totalRows_data_menu") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_data_menu = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_data_menu = sprintf("&totalRows_data_menu=%d%s", $totalRows_data_menu, $queryString_data_menu);
?>

<div class="row">
<div class="col-md-3">
<form id="form1" name="form1" method="get" action="">
  <select name="sort" id="sort" onchange="this.form.submit()" class="form-control"  >
    <option <?php if ($_GET['sort']=='yes'){ ?>selected="selected"<?php } ?> value="yes">Sort Submenu</option>
    <option <?php if ($_GET['sort']=='no'){ ?>selected="selected"<?php } ?> value="no">No Sort Submenu</option>
  </select>
  <input type="hidden" name="page" value="page"> 
</form>
</div>
<div class="col-md-6"></div>
<div class="col-md-3" align="right">
  <a href="?page=defaultlayout">
  <button type="submit" class="btn btn-default">Default on page layout</button>
  </a></div>
</div>
<hr>
<?php if ($totalRows_data_menu>0) { ?>
<table id="example-datatable" class="table table-bordered table-hover dataTable" aria-describedby="example-datatable_info">
  <tr>
        <td width="50"><strong>No</strong></td>
        <td><strong>Title Menu</strong></td>
        <td><strong>Link Menu</strong></td>
        <td width="100"><strong>Action</strong></td>
      </tr>
      <?php $i=1; do { ?>
        <tr>
          <td><?php echo $i++; ?></td>
          <td><?php echo $row_data_menu['judul_m']; ?></td>
          <td><?php echo $row_data_menu['link_m']; ?></td>
          <td><div class="btn-group">
<a href="?page=sett_review_page&idmenu=<?php echo $row_data_menu['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Sett Review"><i class="fa fa-eye"></i></a>
<a href="?page=edit_page&idmenu=<?php echo $row_data_menu['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Edit"><i class="fa fa-pencil"></i></a>
<a href="page/del_page.php?id_menu=<?php echo $row_data_menu['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Delete"><i class="fa fa-times"></i></a>
</div></td>
        </tr>
<?php
if ($_GET['sort']<>'no'){
$colname_p = "-1";
if (isset($row_data_menu['id'])) {
  $colname_p = $row_data_menu['id'];
}
mysql_select_db($database_konek, $konek);
$query_p = sprintf("SELECT * FROM menu WHERE parent_m = %s", GetSQLValueString($colname_p, "int"));
$p = mysql_query($query_p, $konek) or die(mysql_error());
$row_p = mysql_fetch_assoc($p);
$totalRows_p = mysql_num_rows($p);

if ($totalRows_p>0){
?>
		<?php do { ?>
		<tr>
          <td><?php echo $i++; ?></td>
          <td><?php echo $row_data_menu['judul_m']; ?> &gt; <?php echo $row_p['judul_m']; ?></td>
          <td><?php echo $row_p['link_m']; ?></td>
          <td><div class="btn-group">
<a href="?page=sett_review_page&idmenu=<?php echo $row_p['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Sett Review"><i class="fa fa-eye"></i></a>
<a href="?page=edit_page&idmenu=<?php echo $row_p['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Edit"><i class="fa fa-pencil"></i></a>
<a href="page/del_page.php?id_menu=<?php echo $row_p['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Delete"><i class="fa fa-times"></i></a>
</div></td>
        </tr>

<?php
$colname_p2 = "-1";
if (isset($row_p['id'])) {
  $colname_p2 = $row_p['id'];
}
mysql_select_db($database_konek, $konek);
$query_p2 = sprintf("SELECT * FROM menu WHERE parent_m = %s", GetSQLValueString($colname_p2, "int"));
$p2 = mysql_query($query_p2, $konek) or die(mysql_error());
$row_p2 = mysql_fetch_assoc($p2);
$totalRows_p2 = mysql_num_rows($p2);

if ($totalRows_p2>0){
?>
		<?php do { ?>
		<tr>
          <td><?php echo $i++; ?></td>
          <td><?php echo $row_data_menu['judul_m']; ?> &gt; <?php echo $row_p['judul_m']; ?> &gt; <?php echo $row_p2['judul_m']; ?></td>
          <td><?php echo $row_p2['link_m']; ?></td>
          <td><div class="btn-group">
<a href="?page=sett_review_page&idmenu=<?php echo $row_p2['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Sett Review"><i class="fa fa-eye"></i></a>
<a href="?page=edit_page&idmenu=<?php echo $row_p2['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Edit"><i class="fa fa-pencil"></i></a>
<a href="page/del_page.php?id_menu=<?php echo $row_p2['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Delete"><i class="fa fa-times"></i></a>
</div></td>
        </tr>
        
 <?php
$colname_p3 = "-1";
if (isset($row_p2['id'])) {
  $colname_p3 = $row_p2['id'];
}
mysql_select_db($database_konek, $konek);
$query_p3 = sprintf("SELECT * FROM menu WHERE parent_m = %s", GetSQLValueString($colname_p3, "int"));
$p3 = mysql_query($query_p3, $konek) or die(mysql_error());
$row_p3 = mysql_fetch_assoc($p3);
$totalRows_p3 = mysql_num_rows($p3);

if ($totalRows_p3>0){
?>
		<?php do { ?>
		<tr>
          <td><?php echo $i++; ?></td>
          <td><?php echo $row_data_menu['judul_m']; ?> &gt; <?php echo $row_p['judul_m']; ?> &gt; <?php echo $row_p2['judul_m']; ?> &gt; <?php echo $row_p3['judul_m']; ?></td>
          <td><?php echo $row_p3['link_m']; ?></td>
          <td><div class="btn-group">
<a href="?page=sett_review_page&idmenu=<?php echo $row_p3['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Sett Review"><i class="fa fa-eye"></i></a>
<a href="?page=edit_page&idmenu=<?php echo $row_p3['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Edit"><i class="fa fa-pencil"></i></a>
<a href="page/del_page.php?id_menu=<?php echo $row_p3['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Delete"><i class="fa fa-times"></i></a>
</div></td>
        </tr>

 <?php
$colname_p4 = "-1";
if (isset($row_p3['id'])) {
  $colname_p4 = $row_p3['id'];
}
mysql_select_db($database_konek, $konek);
$query_p4 = sprintf("SELECT * FROM menu WHERE parent_m = %s", GetSQLValueString($colname_p4, "int"));
$p4 = mysql_query($query_p4, $konek) or die(mysql_error());
$row_p4 = mysql_fetch_assoc($p4);
$totalRows_p4 = mysql_num_rows($p4);

if ($totalRows_p4>0){
?>
		<?php do { ?>
		<tr>
          <td><?php echo $i++; ?></td>
          <td><?php echo $row_data_menu['judul_m']; ?> &gt; <?php echo $row_p['judul_m']; ?> &gt; <?php echo $row_p2['judul_m']; ?> &gt; <?php echo $row_p3['judul_m']; ?> &gt; <?php echo $row_p4['judul_m']; ?></td>
          <td><?php echo $row_p4['link_m']; ?></td>
          <td><div class="btn-group">
<a href="?page=sett_review_page&idmenu=<?php echo $row_p4['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Sett Review"><i class="fa fa-eye"></i></a>
<a href="?page=edit_page&idmenu=<?php echo $row_p4['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Edit"><i class="fa fa-pencil"></i></a>
<a href="page/del_page.php?id_menu=<?php echo $row_p4['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Delete"><i class="fa fa-times"></i></a>
</div></td>
        </tr>
         <?php } while ($row_p4 = mysql_fetch_assoc($p4)); 
		 mysql_free_result($p4); }
		 ?>        

         <?php } while ($row_p3 = mysql_fetch_assoc($p3)); 
		 mysql_free_result($p3); }
		 ?>
 
         <?php } while ($row_p2 = mysql_fetch_assoc($p2)); 
		 mysql_free_result($p2); }
		 ?>        

         <?php } while ($row_p = mysql_fetch_assoc($p)); 
		 mysql_free_result($p); }
}
		 ?>
         
        <?php } while ($row_data_menu = mysql_fetch_assoc($data_menu)); 
		?>
  </table>
    <?php if ($totalRows_data_menu>20) { ?>
    <table id="example-datatable" class="table table-bordered table-hover dataTable" aria-describedby="example-datatable_info" style="width:200px">
      <tr>
        <td><?php if ($pageNum_data_menu > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_data_menu=%d%s", $currentPage, 0, $queryString_data_menu); ?>">First</a>
            <?php } // Show if not first page ?></td>
        <td><?php if ($pageNum_data_menu > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_data_menu=%d%s", $currentPage, max(0, $pageNum_data_menu - 1), $queryString_data_menu); ?>">Previous</a>
            <?php } // Show if not first page ?></td>
        <td><?php if ($pageNum_data_menu < $totalPages_data_menu) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_data_menu=%d%s", $currentPage, min($totalPages_data_menu, $pageNum_data_menu + 1), $queryString_data_menu); ?>">Next</a>
            <?php } // Show if not last page ?></td>
        <td><?php if ($pageNum_data_menu < $totalPages_data_menu) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_data_menu=%d%s", $currentPage, $totalPages_data_menu, $queryString_data_menu); ?>">Last</a>
            <?php } // Show if not last page ?></td>
      </tr>
    </table>
    <?php } ?>
    <?php } ?><br />
<br />


<?php

mysql_free_result($data_menu);
?>
